package com.bc.bcsellerapihttp.controller;

import com.bc.bcapi.service.T_User_mytokenService;
import com.bc.bcmodel.SellerUserInfo;
import com.bc.bcmodel.domain.T_User_seller_infoModel;
import com.bc.bcmodel.req.UpdateOutWalletReq;
import com.bc.bcsellerapihttp.common.UserContext;
import com.bc.bcmodel.req.NewOutWalletReq;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;

@RestController
@RequestMapping("outsidewallet")
@Api(value = "用户场外钱包接口")
public class OutWalletController {

    @Autowired
    T_User_mytokenService t_user_mytokenService;

    @ApiOperation("查询用户所有有效场外钱包")
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public JsonResult list () {
        SellerUserInfo loginInfo = UserContext.getCurrentContext().getLoginInfo();
        JsonResult js = new JsonResult();
        if (loginInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }

        //查库
        js.setData(t_user_mytokenService.getUserInuseOutWallet(loginInfo.getUser_id()));
        return js;
    }

    @ApiOperation("新增用户场外钱包")
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public JsonResult add (@RequestBody NewOutWalletReq req) {
        SellerUserInfo loginInfo = UserContext.getCurrentContext().getLoginInfo();
        JsonResult js = new JsonResult();
        if (loginInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }

        return t_user_mytokenService.create(req, loginInfo.getUser_id());
    }

    @ApiOperation("更新用户场外钱包")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public JsonResult update (@RequestBody UpdateOutWalletReq req) {
        SellerUserInfo loginInfo = UserContext.getCurrentContext().getLoginInfo();
        JsonResult js = new JsonResult();
        if (loginInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }

        return t_user_mytokenService.updateWallet(req, loginInfo.getUser_id());
    }

    @ApiOperation("删除用户场外钱包")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public JsonResult delete (@RequestBody UpdateOutWalletReq req) {
        SellerUserInfo loginInfo = UserContext.getCurrentContext().getLoginInfo();
        JsonResult js = new JsonResult();
        if (loginInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }

        return t_user_mytokenService.deleteWallet(req, loginInfo.getUser_id());
    }

    @ApiOperation("查询id查询用户有效场外钱包")
    @RequestMapping(value = "show",method = RequestMethod.GET)
    public JsonResult show (@RequestParam(value = "id", required = true) BigInteger id) {
        SellerUserInfo loginInfo = UserContext.getCurrentContext().getLoginInfo();
        JsonResult js = new JsonResult();
        if (loginInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }

        return t_user_mytokenService.getById(loginInfo.getUser_id(), id);
    }

}
